package com.example.offer.no0009.impl;

import java.util.Stack;

import com.example.offer.no0009.Solution;

/**
 * @author yumuhui <yumuhui@kuaishou.com>
 * Created on 2021-05-13
 */
public class SolutionImpl implements Solution {

    // 两个栈，一个出栈，一个入栈
    private Stack<Integer> stackIn;
    private Stack<Integer> stackOut;

    @Override
    public void CQueue() {
        stackIn = new Stack<>();
        stackOut = new Stack<>();
    }

    @Override
    public void appendTail(int value) {
        stackIn.push(value);
    }

    @Override
    public int deleteHead() {

        if (!stackOut.isEmpty()) {
            return stackOut.pop();
        }

        if (stackIn.isEmpty()) {
            return  -1;
        }

        while (!stackIn.isEmpty()) {
            stackOut.push(stackIn.pop());
        }

        return stackOut.pop();
    }
}
